package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.bean.SelectBankByCaseBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 项目名称：TopSeller
 * 类描述：
 * 创建时间：2017/7/4 0004 17:48
 * 创建人：wangye
 * 修改备注：
 */

public class ChoseCardAdapter extends RecyclerView.Adapter<ChoseCardAdapter.MyViewHolder> {

    private Context context;
    private List<SelectBankByCaseBean.BankListBean> bankListBeen;
    clickItemListener clickItemListener;

    public void setClickItemListener(ChoseCardAdapter.clickItemListener clickItemListener) {
        this.clickItemListener = clickItemListener;
    }

    public void setBankListBeen(List<SelectBankByCaseBean.BankListBean> bankListBeen) {
        this.bankListBeen = bankListBeen;
        notifyDataSetChanged();
    }

    public ChoseCardAdapter(Context context) {
        this.context = context;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_chose_card, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        holder.bank.setText(bankListBeen.get(position).getBank());
        holder.backCase.setText(bankListBeen.get(position).getBackCase());
        holder.bankNumber.setText(bankListBeen.get(position).getBankNumber());
        if ("1".equals(bankListBeen.get(position).getIfDefault())){
            holder.circle.setImageResource(R.drawable.select1);
        }else {
            holder.circle.setImageResource(R.drawable.unselect1);
        }
        holder.layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                clickItemListener.clickItem(position,bankListBeen.get(position).getIfDefault(),bankListBeen.get(position).getId());
            }
        });
    }

    @Override
    public int getItemCount() {
        return bankListBeen == null ? 0 : bankListBeen.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.bank)
        TextView bank;
        @BindView(R.id.layout)
        RelativeLayout layout;
        @BindView(R.id.bankNumber)
        TextView bankNumber;
        @BindView(R.id.backCase)
        TextView backCase;
        @BindView(R.id.circle)
        ImageView circle;
        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
    public interface clickItemListener{
        void clickItem(int position,String isDefault,String id);
    }
}
